<?php 
include_once('processAjax.php');
include_once('../../DataProvider.php');


	function ClearSession()
	{
		$_SESSION['artwork']= '';
		$_SESSION['img1']= '';
		$_SESSION['img2']= '';
		$_SESSION['img3']= '';
		$_SESSION['img4']= '';
		$_SESSION['img5']= '';
		$_SESSION['Size']= '';
		
		}
 ?>

<!-- Verify if user exists for login -->
<?php
if(isset($_POST['arguments1']))
{
	
	$TenGame = $_POST['arguments1']["ten"];;
	$TenGame = str_replace('%20',' ',$TenGame);
    $LinkGame = $_POST['arguments1']['mlink'];
    $Price = (int)$_POST['arguments1']["pri"];
    $type = (int)$_POST['arguments1']["ty"];
	$device = (int)$_POST['arguments1']["de"];
	$hot = (int)$_POST['arguments1']["ho"];

	if(strcmp( $_SESSION["linkGame"] , $LinkGame)!=0)
	{
	ReadUrlLink($LinkGame);
	GetArtworkAndName();
	GetScreenShoot();
	$TenGame = $_SESSION["GameName"];
	
	
	}
	$idGame = substr($LinkGame,strpos($LinkGame,'id'),11);
	$ds = DataProvider::ExecuteQuery("SELECT * FROM tbl_games WHERE GameLink like '%".$idGame."%'");

	if(mysql_fetch_array($ds, MYSQL_ASSOC))
	{ 
		echo "<script type='text/javascript'>alert('Game đã được up!');</script>";
	}
	else
	{
		$size = $_SESSION['Size'];
		date_default_timezone_set("Asia/Ho_Chi_Minh");
		$date =	date('Y-m-d H:i:s');
		for($i=1;$i<6;$i++)
		{
			$_SESSION['img'.$i];
		}
		$sqlin = "INSERT INTO tbl_games (Status,GameName,GameLink,Price,CategoriesID,Artwork,img1,img2,img3,img4,img5,Size,CreateDate,Notes,Device) VALUES ($hot,".'"'.$TenGame.'"'.",'$LinkGame',$Price,$type,'".$_SESSION['artwork']."','".$_SESSION['img1']."','".$_SESSION['img2']."','".$_SESSION['img3']."','".$_SESSION['img4']."','".$_SESSION['img5']."',".$size.",'$date','".$_SESSION['Requires']."',$device)";
		
		$dsGame = DataProvider::ExecuteQueryGetID($sqlin);
		if($dsGame)
		{
			$sql = "update tbl_request set status = 1 where LinkRequest = '$LinkGame'";
			$result = DataProvider::ExecuteQuery($sql);

			ShowScreenShoot();
			$dsGame = str_pad($dsGame,6,"0",STR_PAD_LEFT);
			echo"<script>
			$('#msg').html('Successful!');
			
			$('#msg').fadeIn();

              $('#msg').fadeOut(3000);
$('#upgame').hide();


			</script>";
			ClearSession(); 
		}
		else
		echo"<script type='text/javascript'>alert('Error!'); </script>";
		
	}
}
else 
{
	echo"<script type='text/javascript'>alert('Error get!'); </script>";
}
?>